'use strict';
const {verifyToken} =require("wx-common") 

exports.main = async (event, context) => {
	
	const payload =event.token?verifyToken(event.token):null
	//event为客户端上传的参数
	const db=uniCloud.database()
	const dbCmd=db.command
	
	let res;
	if (event.action=='add'){
		res= await db.collection("personPhoto").add({
			owner:payload.openid,
			date:event.date,
			path:event.path,
		})
	} else if (event.action=='query'){
		res=await db.collection("personPhoto").where({
			owner:dbCmd.eq(payload.openid)
		}).orderBy('_id','asc').get()
	}
	
	return res
};
